﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_ReadDocument]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_ReadDocument];
GO
CREATE PROCEDURE [dbo].[sproc_ReadDocument]
    @Doc_ID int,
    @UserName nvarchar(300)=''
/*

============================================================
功能:    读文档
参数:
    @Doc_ID int            :    被读文档ID
    @UserName nvarchar(300)=''    :    读文档人

============================================================

*/
AS
BEGIN

SET NOCOUNT ON
SELECT a.*, b.ClassName, c.FileName, c.FileSize, c.FileAttribute, c.FileVisualPath, c.FileAuthor, c.FileAddedDate, c.FileCatlog
    FROM
        uds_document a
        left outer join uds_files c on a.DocID = c.DocID
        left outer join uds_class b on a.classid = b.classid
    WHERE
        a.docid = @Doc_ID

UPDATE uds_document
    SET
        doclastviewer = @username,
        doclastviewdate = getdate(),
        docviewedtimes = docviewedtimes + 1
    WHERE docid = @Doc_ID

END
GO